package info.yaohua;

import info.dao.Ac01Dao;
import info.dao.Ac02Dao;
import info.util.SessionNull;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Check_Bzr_Servlet extends HttpServlet
	{
		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException
			{
				// TODO Auto-generated method stub
				HttpSession session=req.getSession(false);
				if(session==null)
					{
						SessionNull.forwordTo(req, resp);
					}
				else
					{
						String username = req.getParameter("username");
						Ac02Dao ac02Dao=new Ac02Dao();
						try
							{
								boolean success=ac02Dao.findUserByUsername(username);
								if(success)
									{
										PrintWriter write=resp.getWriter();
										write.println(0);
									}
								else
									{
										PrintWriter write=resp.getWriter();
										write.println(1);
									}
							}
						catch (NamingException | SQLException e)
							{
								// TODO Auto-generated catch block
								e.printStackTrace();
							} 
					}
			}

		@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException
			{
				// TODO Auto-generated method stub
				super.doPost(req, resp);
			}
	}
